home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 142 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.8 KB

  1. From: jbuck@Synopsys.COM (Joe Buck)
  2. Message-ID: <4e8g4t$aa3@hermes.synopsys.com>
  3. X-Original-Date: 25 Jan 1996 17:54:37 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 26 Jan 96 04:56:51 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Give operator. a chance
  9. Organization: Synopsys Inc., Mountain View, CA 94043-4033
  10. References: <3102AD11.1663@et.se>
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBFAgUBMQhgPeEDnX0m9pzZAQFuvAGAju5TDq3YHUH8hirK7WC0GeuI9w4OpKtx
  13.     5MhRoJovKvd6B3cqTjVpG28m13Tc8R25
  14.     =4KRC
  15.  
  16. Dan Holmsand <dan@et.se> writes:
  17. >Is operator.() banned from the standards discussion?
  18.  
  19. Yes, I suppose it is, but since you brought it up I'll discuss it anyway.
  20.  
  21. A formal proposal to add it (from Jim Adcock of Microsoft) was voted down
  22. some time ago.  The Adcock proposal was quite simple: "operator dot" would
  23. work just like operator-> except that where operator-> returns a pointer,
  24. operator. would return a reference.  The language in the standard would
  25. be almost identical except for simple substitutions of words.  The
  26. advantage of this was that it would be absolutely clear what the
  27. modification would mean and what the language should be.
  28.  
  29. Some committee members objected that it's against the philosophy of C++ to
  30. change the meaning of a builtin operator ("."  operating on class object)
  31. -- though we already have operator& whose builtin meaning can be changed.
  32.  
  33. Others favored a more complex and non-orthogonal version, or, worse, first
  34. said the proposal should be more complex and non-orthogonal and then
  35. objected to the complexity and non-orthogonality in this modified version.
  36.  
  37. Others objected that if both operator. and operator-> were overloaded the
  38. class would be just about impossible to implement, ignoring the fact that
  39. no one (who understands that providing operator-> gives your object
  40. pointer semantics and operator. gives your object reference semantics, and
  41. you'd want to choose only one) would do this.
  42.  
  43. Others (those I respect the most) just said they didn't want extensions
  44. without an extremely strong reason, didn't see a strong enough reason for
  45. operator dot, but just wanted to get C++ standardized.  This does make
  46. sense (it would make more sense if so many *other* extensions had not been
  47. accepted).
  48.  
  49. I think that this rejection was a mistake, as the lack of operator dot
  50. complicates the implementation of delegation (e.g. in classes that use a
  51. reference-counted representation object where the representation object
  52. has virtual functions).  I subscribe to the "write things once"
  53. philosophy, and hate long lists like
  54.  
  55. class Foo {
  56. private:
  57.     FooRep * rep;
  58. public:
  59.     ...
  60.     void foo() { rep->foo();}
  61.     int bar(int arg) { return rep->foo(arg);}
  62.     ... and about a dozen more
  63. };
  64.  
  65. With operator. this would become
  66.  
  67. class Foo {
  68. private:
  69.     FooRep * rep;
  70. public:
  71.     FooRep& operator.() { return *rep;}
  72. };
  73.  
  74. and now you can call foo(), bar(int) etc on objects of class Foo.  It
  75. is possible, but confusing, to use operator-> here, but then the Foo
  76. object looks like a pointer, and this isn't the type of programming
  77. interface that is desired in this situation.
  78.  
  79. But it's too late for major changes at this stage; what's more important
  80. is to complete the standard.  We lost the vote, and it's time to move on.
  81.  
  82. In the meantime, anyone who wants to experiment with the idea can probably
  83. track down g++ patches that implement operator dot along the lines of
  84. the Adcock proposal -- I've seen mention of these on the net, but I
  85. don't know where they are.
  86.  
  87. -- 
  88. -- Joe Buck     <jbuck@synopsys.com>    (not speaking for Synopsys, Inc)
  89.  
  90. Work for something because it is good,
  91. not just because it stands a chance to succeed.       -- Vaclav Havel
  92. ---
  93. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  94.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  95.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  96.